package com.ag.zlw.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbGoodstype;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.zlw.service.GoodsTypeService;

/**
 * 物品类型
 * 
 * @author 钟龙伟
 * 
 */

@Scope("prototype")
@Controller("GoodsTypeAction")
public class GoodsTypeAction extends BaseAction {
	private static final long serialVersionUID = -1478025497648926124L;
	@Resource(name = "GoodsTypeService")
	private GoodsTypeService service;
	private List<TbGoodstype> GoodsTypeList;
	private String message;
	private String gtId;
	private String gtName;

	TbGoodstype tbGoodstype = new TbGoodstype();

	public String find() {
		try {
			GoodsTypeList = service.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "main";
	}

	public String delete() {
		tbGoodstype.setGtId(gtId);
		try {
			service.delete(tbGoodstype);
			this.setMessage("delete success!");
		} catch (Exception e) {
			this.setMessage("delete fail!");
		}
		return "delete_success";
	}

	public String add() {
		tbGoodstype.setGtName(gtName);
		tbGoodstype.setA(IDUtil.PRESERVE);
		try {
			service.save(tbGoodstype);
			this.setMessage("save success!");
		} catch (Exception e) {
			this.setMessage("save fail!");
		}
		return "add_success";
	}

	public String modify() {
		tbGoodstype.setGtId(gtId);
		tbGoodstype.setGtName(gtName);
		tbGoodstype.setA(IDUtil.PRESERVE);
		try {
			service.modify(tbGoodstype);
			this.setMessage("modify success!");
		} catch (Exception e) {
			this.setMessage("modify fail!");
		}
		return "modify_success";
	}

	public List<TbGoodstype> getGoodsTypeList() {
		return GoodsTypeList;
	}

	public void setGoodsTypeList(List<TbGoodstype> goodsTypeList) {
		GoodsTypeList = goodsTypeList;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getGtId() {
		return gtId;
	}

	public void setGtId(String gtId) {
		this.gtId = gtId;
	}

	public String getGtName() {
		return gtName;
	}

	public void setGtName(String gtName) {
		this.gtName = gtName;
	}
}
